﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace _0812045
{
    public class ScrollingMap
    {
        private Vector2 pointToDraw1;
        private Vector2 pointToDraw2;
        PictureSprite[] _sprite;
        public int y = 0;
        public bool Init(ContentManager Content, string level, string strResource)
        {
            _sprite = new PictureSprite[1];

            Texture2D[] texture2D;
            texture2D = new Texture2D[1];
            texture2D[0] = Content.Load<Texture2D>(@"Levels/" + level + "/" + strResource);

            _sprite[0] = new PictureSprite(texture2D);
            pointToDraw1 = new Vector2(0, y);
            pointToDraw2 = new Vector2(texture2D[0].Width, y);
            return true;
        }
        int iDelay = 0;
        public int nDelay;
        public void Update(GameTime gameTime)
        {
            if (iDelay == 0)
            {
                pointToDraw1.X -= 1;
                pointToDraw2.X -= 1;
            }
            iDelay = (iDelay + 1) % nDelay;
            if (pointToDraw1.X < -_sprite[0].texture2d[0].Width)
            {
                pointToDraw1 = pointToDraw2;
                pointToDraw2.X = pointToDraw1.X + _sprite[0].texture2d[0].Width;
            }
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            _sprite[0].Draw(gameTime, spriteBatch, pointToDraw1);
            _sprite[0].Draw(gameTime, spriteBatch, pointToDraw2);
        }
    }
}
